/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package foxmob.mlts.model;

import foxmob.mlts.component.FileManager;
import java.util.*;

/**
 *
 * @author Emmanouil Samatas
 */
public class Subsection {
    private String title;
    private String description;
    private FileManager fileManager;
    private String ID;
    private ArrayList<Question> questions ;
     
    
    public Subsection() {
        questions = new ArrayList<Question>();
        UUID id = UUID.randomUUID();
       ID = id.toString();
    }
    
    @Override
    public String toString() {
        return title;
    }
    
    public void setID(String ID) {
        this.ID = ID;
    }
    
    public String getID() {
        return ID;
    }
    
    public void setQuestion(ArrayList<Question> questionInSub) {
        questions = questionInSub;
    }
       
    public void addQuestion(Question question) {        
        // add to question array
        this.questions.add(question);
    }
    
    public void addQuestion(ArrayList<Question> question) {
        // loop through a list of question
        for (Question q : question) {
            addQuestion(q);
        }
    }
    
    public void removeQuestion(Question question) {
        this.questions.remove(question);
    }
    
    public void removeQuestion(ArrayList<Question> question) {
        // loop through a list of section
        for (Question q : question) {
            removeQuestion(q);
        }
    }
    
    public boolean isExistQuestion(Question question) {
        for (Question quest : this.questions) {
            if (quest.getQuestionText().equals(question.getQuestionText())) {
                return true;
            }
        }
        return false;
    }
    
    public void modifyQuestion(Question question) {
        int i = 0;
        for (Question q : questions) {
            if (q.getID().equals(question.getID())) {
                 break;
            }
            ++i;
        }
        this.questions.set(i, question);
    }
    
    public int getQuestionsLength() {
        return questions.size();
    }
    
    public Question getQuestionWithID(String ID) {
        for (Question q : questions) {
            if (q.getID().equals(ID)) {
                return q; 
            }
        }
        return null;
    }
    
    public ArrayList<Question> getQuestions() {
        return questions;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public String getDescription() {
        return description;
    }
}
